package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hencoder.hencoderpracticedraw1.R;

public class Practice9DrawPathView extends View {
    private Paint paint;
    private int w;
    private int h;


    public Practice9DrawPathView(Context context) {
        super(context);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.w=w;
        this.h=h;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        练习内容：使用 canvas.drawPath() 方法画心形  372,252
        float centerW=w/2;
        float centerH=h/2;
        paint=new Paint();
        paint.setColor(getResources().getColor(R.color.colorAccent));
        Path path=new Path();
        path.addArc(centerW-200,centerH-200,centerW,centerH,140,220);
        path.arcTo(centerW,centerH-200,centerW+200,centerH,180,220,false);
        path.lineTo(centerW,centerH+200);
        canvas.drawPath(path,paint);

    }
}
